import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PanelLogowania extends JPanel{
    private final String LOGIN = "mariola";
    private final String HASLO = "12345";

    private JTextField loginTF;
    private JPasswordField hasloTF;

    public PanelLogowania(){
        ustawPanel();
        ustawKomponenty();
    }

    private void ustawPanel(){
    }

    private void ustawKomponenty() {
         setLayout(new GridLayout(3, 2, 0, 10));

        JLabel loginLbl = new JLabel("Login: ");
        loginTF = new JTextField();
        JLabel hasloLbl = new JLabel("Hasło: ");
        hasloTF = new JPasswordField();
        JButton przycisk = new JButton("Zaloguj");
        przycisk.addActionListener(new SluchaczPrzyciskuZaloguj());

        add(loginLbl);
        add(loginTF);
        add(hasloLbl);
        add(hasloTF);
        add(new JLabel());
        add(przycisk);
    }

    class SluchaczPrzyciskuZaloguj implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e) {
            String login = loginTF.getText();
            char[] hasloTablicaChar = hasloTF.getPassword();
            String hasloString = String.valueOf(hasloTablicaChar);

            if (login.equals(LOGIN) && hasloString.equals(HASLO)){
                JOptionPane.showMessageDialog(
                        null,
                        "Zalogowano",
                        "Info",
                        JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(
                        null,
                        "Błędne dane",
                        "Info",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}
